package test.baojia.act.operation;

import com.alibaba.fastjson.JSONObject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.util.Properties;

public class ClickMenuOperation extends Operation {

    @Override
    public void run(JSONObject context, WebDriver driver, Properties resource, JSONObject parentContext) throws Exception{
        super.run(context, driver, resource, parentContext);
        driver.switchTo().defaultContent();

        final String menuName = (String) context.get("menuName");
        //driver.findElement(By.linkText(menuName)).click();
        driver.findElement(By.partialLinkText(menuName)).click();

        super.toMainFrame();
        //final String srcExpected = resource.getProperty("menu." + menuName).trim();

        this.newWebDriverWait(null).until(
                //ExpectedConditions.attributeContains(MAIN_FRAME_BY , "src" , srcExpected)
                ExpectedConditions.textToBePresentInElementLocated(MAIN_FRAME_BY_NAME,menuName)
        );

    }
}
